package com.mab.apipassenger.service;

import com.mab.apipassenger.remote.ServicePriceClient;
import com.msb.internalcommon.dto.ResponseResult;
import com.msb.internalcommon.reponese.DirectionResponse;
import com.msb.internalcommon.reponese.ForecastPriceResponse;
import com.msb.internalcommon.request.ForecastPriceDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: jiudianliu
 * @Date: 2023/6/2 - 06 - 02 - 13:50
 * @Description: com.mab.apipassenger.service
 * @version: 1.0
 */
@Service
@Slf4j
public class ForecastPriceService {

    @Autowired
    private ServicePriceClient servicePriceClient ;


    /**
     * 根据  出发地和目的地的经纬度  计算预估价格
     * @param depLongitude
     * @param depLatitude
     * @param destLongitude
     * @param destLatitude
     * @return
     */
    public ResponseResult forecastPrice(String depLongitude, String depLatitude, String destLongitude, String destLatitude , String cityCode , String vehicleType){

        log.info("出发地的经度：" + depLongitude);
        log.info("出发地的纬度：" + depLatitude);
        log.info("目的地的经度：" + destLongitude);
        log.info("目的地的经度：" + destLatitude);

        log.info("调用计价服务，计算价格") ;
        ForecastPriceDTO forecastPriceDTO = new ForecastPriceDTO();
        forecastPriceDTO.setDepLongitude(depLongitude);
        forecastPriceDTO.setDepLatitude(depLatitude);
        forecastPriceDTO.setDestLongitude(destLongitude);
        forecastPriceDTO.setDestLatitude(destLatitude);
        forecastPriceDTO.setCityCode(cityCode);
        forecastPriceDTO.setVehicleType(vehicleType);
        ResponseResult<ForecastPriceResponse> forcast = servicePriceClient.forecast(forecastPriceDTO);
        double price = forcast.getData().getPrice();

        ForecastPriceResponse forecastPriceResponse = new ForecastPriceResponse() ;
        forecastPriceResponse.setPrice(price);
        forecastPriceResponse.setCityCode(cityCode);
        forecastPriceResponse.setVehicleType(vehicleType);
        return ResponseResult.success(forecastPriceResponse) ;
    }
}
